<?php

class Project extends Public_Controller {

	function __construct()
	{
		parent::__construct();	
	}
	
	
	public function zip($project_id = false)
	{
		$this->sSkinFile = 'ajax';
		
		if($project_id > 0)
		{
			$this->load->model('db/views/baa_projects_extended', 'baa_projects');
			$this->baa_projects->project_id = $project_id;
			
			$qProject = $this->baa_projects->get(1);
			
			if($qProject->num_rows() === 1)
			{
				$this->load->library('zip');
				
				$img_url = './assets/media/original/'.$qProject->row(0)->jpg_media_subfolder.'/'.$qProject->row(0)->jpg_media_id.'.'.$qProject->row(0)->jpg_extension_ext;
				
				$sImg = file_get_contents($img_url);
				
				$sImgName = 'project_'.$project_id.'_image.'.$qProject->row(0)->jpg_extension_ext;
				$this->zip->add_data($sImgName, $sImg);
				
				if($qProject->row(0)->pdf_media_id > 0)
				{
					$pdf_url = './assets/media/web/'.$qProject->row(0)->pdf_media_subfolder.'/'.$qProject->row(0)->pdf_media_id.'.'.$qProject->row(0)->pdf_extension_ext;
					
					$sPdf = file_get_contents($pdf_url);
					
					$sPdfName = 'project_'.$project_id.'_pdf.'.$qProject->row(0)->pdf_extension_ext;
					$this->zip->add_data($sPdfName, $sPdf);
				}
				
				$this->zip->download('project_'.$project_id.'_media.zip');
			}
		}
	}
}

?>